package com.apexedu.biz.action;

import com.apexedu.biz.entity.TRegulation;
import com.apexedu.biz.service.impl.RegulationServiceImpl;
import com.apexedu.framework.service.BaseService;
import com.apexedu.sys.action.AbstractBaseActionSupport;
import com.apexedu.util.StringUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;

/**
 * 规则管理，类似与新闻发布
 * date:2013.11.27
 * user:liuxu
 */
@SuppressWarnings("serial")
@Component
@Scope("prototype")
public class RegulationAction extends AbstractBaseActionSupport {
    private static final Log LOG = LogFactory.getLog(RegulationAction.class);
	 /**
     * 此方法植入service类
     */
    @Resource(name="regulationService")
    public void setBaseService(BaseService baseService){
        super.setBaseService(baseService);
    }

    @Resource(name="regulationService")
    RegulationServiceImpl regulationService;

    private TRegulation regulation;
    private String selectedGZ;      //已经选择的规则
    private String selectedZY;      //已经选择的资源
    private String zywid;           //资源wid
    private String gzwid;           //规则WID
    private String jsonDate;        //用json的形式保存 wid与标题的对应关系
    private String zyTreeJsonData;  //资源树的JSON数据


    private File fj;                   //附件
    private String fjFileName;         //文件名
    private String fjContentType;      // 封装上传文件类型的属性

    private File dyzdsc;                //对应制度上传
    private String dyzdscFileName;      //文件名

    private File ysxqfj;        //原始需求附件
    private String ysxqfjFileName;        //原始需求附件文件名


    private File gzzdfj;        //规章制度附件
    private String gzzdfjFileName;        //规章制度附件文件名


    public TRegulation getRegulation() {
        return regulation;
    }

    public void setRegulation(TRegulation regulation) {
        this.regulation = regulation;
    }

    public String getSelectedGZ() {
        return selectedGZ;
    }

    public void setSelectedGZ(String selectedGZ) {
        this.selectedGZ = selectedGZ;
    }

    public String getZywid() {
        return zywid;
    }

    public void setZywid(String zywid) {
        this.zywid = zywid;
    }


    public String getJsonDate() {
        return jsonDate;
    }

    public void setJsonDate(String jsonDate) {
        this.jsonDate = jsonDate;
    }

    public String getGzwid() {
        return gzwid;
    }

    public void setGzwid(String gzwid) {
        this.gzwid = gzwid;
    }

    public String getSelectedZY() {
        return selectedZY;
    }

    public void setSelectedZY(String selectedZY) {
        this.selectedZY = selectedZY;
    }

    public String getZyTreeJsonData() {
        return zyTreeJsonData;
    }

    public void setZyTreeJsonData(String zyTreeJsonData) {
        this.zyTreeJsonData = zyTreeJsonData;
    }

    public File getFj() {
        return fj;
    }

    public void setFj(File fj) {
        this.fj = fj;
    }

    public String getFjFileName() {
        return fjFileName;
    }

    public void setFjFileName(String fjFileName) {
        this.fjFileName = fjFileName;
    }

    public String getFjContentType() {
        return fjContentType;
    }

    public void setFjContentType(String fjContentType) {
        this.fjContentType = fjContentType;
    }

    public String getDyzdscFileName() {
        return dyzdscFileName;
    }

    public void setDyzdscFileName(String dyzdscFileName) {
        this.dyzdscFileName = dyzdscFileName;
    }

    public File getDyzdsc() {
        return dyzdsc;
    }

    public void setDyzdsc(File dyzdsc) {
        this.dyzdsc = dyzdsc;
    }

    public File getYsxqfj() {
        return ysxqfj;
    }

    public void setYsxqfj(File ysxqfj) {
        this.ysxqfj = ysxqfj;
    }

    public File getGzzdfj() {
        return gzzdfj;
    }

    public void setGzzdfj(File gzzdfj) {
        this.gzzdfj = gzzdfj;
    }

    public String getYsxqfjFileName() {
        return ysxqfjFileName;
    }

    public void setYsxqfjFileName(String ysxqfjFileName) {
        this.ysxqfjFileName = ysxqfjFileName;
    }

    public String getGzzdfjFileName() {
        return gzzdfjFileName;
    }

    public void setGzzdfjFileName(String gzzdfjFileName) {
        this.gzzdfjFileName = gzzdfjFileName;
    }

    /**
     * 为资源设置关系
     * @return
     */
    public String szgx(){
        try {
            List<?> list = baseService.list(this, getPager());
            setResultData( list );
            if(StringUtil.isBlank(this.getSelectedGZ())){
                this.setSelectedGZ(regulationService.szgxLoad(this.getZywid()));  //加载
            }
            regulationService.szgxJsonData(this);
        } catch (Throwable e) {
            addActionError(getText("MESSAGE_QUERY_FAILURE") +" ["+ e.getMessage() + "]");
        }
        return toView("szgx.jsp");
    }

    /**
     * 为关系设置资源
     * @return
     */
    public String szzy(){
        try{
            regulationService.szzyLoad(this);
        } catch (Throwable e) {
            addActionError(getText("MESSAGE_QUERY_FAILURE") +" ["+ e.getMessage() + "]");
        }
        return toView("szzy.jsp");
    }

    /**
     * 为资源设置关系(保存)
     * @return
     */
    public void szgxSave(){
        try {
            String message = regulationService.szgxSave(this);
            this.putResultStringToView(message);
        } catch (Throwable e) {
            LOG.error(e.getMessage());
            this.putResultStringToView(e.getMessage());
        }

    }

    /**
     * 为关系设置资源(保存)
     * @return
     */
    public void szzySave(){
        try {
            String message = regulationService.szzySave(this);
            this.putResultStringToView(message);
        } catch (Throwable e) {
            LOG.error(e.getMessage());
            this.putResultStringToView(e.getMessage());
        }

    }
}
